// mmo_game_server/security/ddos_defense.cpp
#include "ddos_defense.h"

DDoSDefense::DDoSDefense() : maxRequestsPerSecond(10) {}

DDoSDefense::~DDoSDefense() {}

bool DDoSDefense::CheckIP(const std::string& ip) {
    auto now = std::chrono::steady_clock::now();
    auto it = ipTimestamps.find(ip);
    if (it == ipTimestamps.end()) {
        ipTimestamps[ip] = now;
        return true;
    }
    auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - it->second).count();
    if (elapsed < 1) {
        return false;
    }
    ipTimestamps[ip] = now;
    return true;
}